<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
class BaseController extends Controller
{
    //定义分页数量
    protected $pagesize = 10;
    public function  __construct()
    {
        $this->pagesize = config('page.pagesize');
    }
    //分页
    public function getPage($model,$where){
        $page  = request()->input('page',0);
        $limit = min(100,request()->input('limit',10)) ;
        //读取已加删除的所有 数据User::withTrashed()
        $query =  DB::table($model)->where($where)->orderBy('id', 'DESC') ;
        $total = $query->count();
        $data = $query->skip(($page - 1) * $limit)->take($limit)->get();
        return [
            'message' => '成功',
            'count' => $total,
            'code'=>0,
            'data' => $data
        ];
    }
    //成功返回
    public function reSuJson($msg,$data=''){
        return response()->json(['code'=>200,'msg'=>$msg,'data'=>$data]);
    }
    //失败返回
    public function reErJson($msg){
        return response()->json(['code'=>0000,'msg'=>$msg]);
    }
}
